package cn.wolfcode.rabc.service.impl;

import cn.wolfcode.rabc.domain.Permission;
import cn.wolfcode.rabc.mapper.PermissionMapper;
import cn.wolfcode.rabc.qo.QueryObject;
import cn.wolfcode.rabc.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Service
public class PermissionServiceImpl implements IPermissionService {


    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    @Transactional
    public void save(Permission permission) {
        permissionMapper.save(permission);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        permissionMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Permission permission) {
        permissionMapper.update(permission);
    }

    @Override
    @Transactional
    public Permission get(Long id) {
        return permissionMapper.get(id);
    }

    @Override
    @Transactional
    public List<Permission> listAll() {
        return permissionMapper.listAll();
    }


    public PageInfo<Permission> query(QueryObject qo){
        // 使用分插件，当传入前页，每页显示数量
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Permission> permissions = permissionMapper.selectForList(qo);
        return new PageInfo(permissions);
    }

    @Override
    public List<Permission> queryByRoleId(Long id) {
        return permissionMapper.queryByRoleId(id);
    }

    @Override
    public List<String> queryExpressionsByEmployeeId(Long id) {
       return permissionMapper.queryExpressionsByEmployeeId(id);

    }


    @Override
    public void batchSave(Set<Permission> permissionSet) {
        permissionMapper.batchSave(permissionSet);
    }
}
